Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-plugin

Package Overview
Dependencies
Maintainers
8
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-plugin

Plugin helper for Fastify

  • 4.5.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2M
decreased by-3.58%
Maintainers
8
Weekly downloads
 
Created

What is fastify-plugin?

The fastify-plugin npm package is designed to facilitate the creation of plugins for the Fastify web framework. It ensures that plugins adhere to specific conventions and are compatible with the Fastify ecosystem. This package helps in encapsulating functionality, adding hooks, decorators, and more, in a way that's easily reusable across different Fastify projects.

What are fastify-plugin's main functionalities?

Plugin Creation

This feature allows developers to create a Fastify plugin. The code sample demonstrates how to use fastify-plugin to decorate the Fastify instance with a new function called 'utility'.

const fp = require('fastify-plugin');

async function myPlugin (fastify, options) {
  fastify.decorate('utility', () => 'something useful');
}

module.exports = fp(myPlugin);

Plugin Options

This feature enables passing options to the plugin, including specifying Fastify version compatibility. The code sample shows how to pass data through options and use it within the plugin.

const fp = require('fastify-plugin');

async function myPlugin (fastify, options) {
  fastify.decorate('usefulData', options.data);
}

module.exports = fp(myPlugin, { name: 'myPlugin', fastify: '3.x' });

Encapsulation

This feature ensures that the plugin does not encapsulate its context, allowing the decorators, hooks, and changes made by the plugin to be available in the parent scope. The code sample demonstrates registering another plugin within a fastify-plugin, ensuring dependencies are managed.

const fp = require('fastify-plugin');

async function myPlugin (fastify, options) {
  fastify.register(require('some-other-plugin'), options);
}

module.exports = fp(myPlugin, { dependencies: ['some-other-plugin'] });

Other packages similar to fastify-plugin

Keywords

FAQs

Package last updated on 18 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc